import axios from "axios";
import { message } from "antd";

const BASE_URL = "http://39.100.225.255:5000";

export default function ajax(url, data = {}, method = "GET") {
  url = BASE_URL + url;
  return new Promise((resolve) => {
    let promise;
    if (method === "GET") {
      if (!data) {
        promise = axios.get(url);
      } else {
        promise = axios.get(url, { params: data });
      }
    } else if (method === "POST") {
      promise = axios.post(url, data);
    }
    promise
      .then((response) => {
        resolve(response.data);
      })
      .catch((err) => {
        message.error("This is an error message" + err);
      });
  });
}
